<?php
class UserModel extends Model {
	protected $_auto = array(
        array('create_time','time',1,'function'),
		
    );
	protected $_validate = array(
	    array('account','','用户名已经存在！',0,'unique',1)
    );
	//获取当前用户所属组
	public function getRole($user_id = 0){
		$db = M('Role_user');
		$role_id = array();
		$ids = $db -> where(array('user_id' => $user_id)) -> select();
		foreach($ids as $k => $v){
			$role_id[] = $v['role_id'];
		}
		return $role_id;
	}
	//获取当前用户所属组
	public function getRole2($user_id = 0){
		$db = M('Member_role_user');
		$role_id = array();
		$ids = $db -> where(array('user_id' => $user_id)) -> select();
		foreach($ids as $k => $v){
			$role_id[] = $v['role_id'];
		}
		return $role_id;
	}
	//获取当前用户可访问的所有节点
	public function getNode($user_id){
		$role_ids = $this->getRole($user_id);
		if(empty($role_ids)) return '';
		$Db = D('Access');
		$map['role_id'] = array('in', $role_ids);
		$nodes = $Db -> where($map) -> select();
		$ret = array();
		foreach($nodes as $v){
			$ret[] = $v['node_id'];
		}
		return $ret;
	}
	//获取当前用户可访问的所有节点
	public function getNode2($user_id){
		$role_ids = $this->getRole2($user_id);
		if(empty($role_ids)) return '';
		$Db = D('Member_access');
		$map['role_id'] = array('in', $role_ids);
		$nodes = $Db -> where($map) -> select();
		$ret = array();
		foreach($nodes as $v){
			$ret[] = $v['node_id'];
		}
		return $ret;
	}
	
	//获取当前用户可管理站点列表
	public function getSiteList($user_id = 0){
		$db = M('Site_user');
	    $ret = $db ->alias('su') -> join("left join __SITE__ as s on s.id = su.site_id")->Field('s.id, s.title')->where(array('su.user_id' => $user_id)) -> select();
		return $ret;
	}
}

?>